<?php

/******************************************
 * File:			lib_date.php
 * Version:			1.0.1
 * Last modified:	25/10/2009
 * Last modifier:	Hugo Lavigne
 *****************************************/

Function get_date_diff($nb_ans, $nb_mois, $nb_jours, $nb_heures, $nb_minutes, $nb_secondes, $mod)
{
	return (date($mod, mktime(date('H')+$nb_heures,date('i')+$nb_minutes,date('s')+$nb_secondes,date('m')+$nb_mois,date('d')+$nb_jours,date('Y')+$nb_ans)));
}

Function get_fr_date($date)
{
	$tmp = explode(' ', $date);
	$date = $tmp[0];
	$time = $tmp[1];
	
	$tmp = explode('-', $date);
	$res['date'] = $tmp[2]."/".$tmp[1]."/".$tmp[0];
	
	$tmp = expldoe(':', $time);
	$res['time'] = $tmp[0].":".$tmp[1];
	
	return ($res);
}

Function show_select_date($name="date", $day=0, $month=0, $year=0)
{
	if (($day == 0) && ($month == 0) && ($year == 0))
	{
		$day = date('d');
		$month = date('m');
		$year = date('Y');
	}
	
	$select_day = "select_date_day_".$name;
	$select_month = "select_date_month_".$name;
	$select_year = "select_date_year_".$name;
	
  Print("
    <table>
      <tr>
        <td>
          <select name=\"$select_day\">
            <option value=\"none\">-</option>
  ");
            $i = 1;
            while ($i < 32)
            {
              if ($i == $day)
              {
                if ($i < 10)
                  Print("<option value=$i selected>0$i</option>");
                else
                  Print("<option value=$i selected>$i</option>");
              }
              else
              {
                if ($i < 10)
                  Print("<option value=$i>0$i</option>");
                else
                  Print("<option value=$i>$i</option>");
              }
              $i++;
            }
  Print("
          </select>
        </td>
        <td>
          <select name=\"$select_month\">
            <option value=\"none\">-</option>
  ");
            $i = 1;
            while ($i < 13)
            {
              if ($i == $month)
              {
                if ($i < 10)
                  Print("<option value=$i selected>0$i</option>");
                else
                  Print("<option value=$i selected>$i</option>");
              }
              else
              {
                if ($i < 10)
                  Print("<option value=$i>0$i</option>");
                else
                  Print("<option value=$i>$i</option>");
              }
              $i++;
            }
  Print("
          </select>
        </td>
        <td>
          <select name=\"$select_year\">
            <option value=\"none\">-</option>
  ");
            $i = date('Y');
            $j = date('Y') + 11;
            while ($i < $j)
            {
              if ($i == $year)
                Print("<option value=$i selected>$i</option>");
              else
                Print("<option value=$i>$i</option>");
              $i++;
            }
  Print("
          </select>
        </td>
      </tr>
    </table>
  ");
  return;
}

Function show_select_date_2($name="date", $day=0, $month=0, $year=0)
{
	if (($day == 0) && ($month == 0) && ($year == 0))
	{
		$day = date('d');
		$month = date('m');
		$year = date('Y');
	}
	
	$select_day = "select_date_day_".$name;
	$select_month = "select_date_month_".$name;
	$select_year = "select_date_year_".$name;
	
  Print("
    <table>
      <tr>
        <td>
          <select name=\"$select_day\">
            <option value=\"none\">-</option>
  ");
            $i = 1;
            while ($i < 32)
            {
              if ($i == $day)
              {
                if ($i < 10)
                  Print("<option value=$i selected>0$i</option>");
                else
                  Print("<option value=$i selected>$i</option>");
              }
              else
              {
                if ($i < 10)
                  Print("<option value=$i>0$i</option>");
                else
                  Print("<option value=$i>$i</option>");
              }
              $i++;
            }
  Print("
          </select>
        </td>
        <td>
          <select name=\"$select_month\">
            <option value=\"none\">-</option>
  ");
            $i = 1;
            while ($i < 13)
            {
              if ($i == $month)
              {
                if ($i < 10)
                  Print("<option value=$i selected>0$i</option>");
                else
                  Print("<option value=$i selected>$i</option>");
              }
              else
              {
                if ($i < 10)
                  Print("<option value=$i>0$i</option>");
                else
                  Print("<option value=$i>$i</option>");
              }
              $i++;
            }
  Print("
          </select>
        </td>
        <td>
          <select name=\"$select_year\">
            <option value=\"none\">-</option>
  ");
            $i = 1920;
            $j = date('Y') - 12;
            while ($i < $j)
            {
              if ($i == $year)
                Print("<option value=$i selected>$i</option>");
              else
                Print("<option value=$i>$i</option>");
              $i++;
            }
  Print("
          </select>
        </td>
      </tr>
    </table>
  ");
  return;
}

?>